package common.utils;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

public class ApplicationUtil {

    /**
     * var app = new SpringApplication(???Application.class);
     * app.addStartedListener(app,runnable);
     * app.run(args);
     */
    public static void addStartedListener(SpringApplication app, Runnable runnable) {
        app.addListeners(new ApplicationListener() {
            @Override
            public void onApplicationEvent(ApplicationEvent applicationEvent) {
                if (applicationEvent.getClass() == ApplicationStartedEvent.class)
                    runnable.run();
            }
        });
    }

}
